package com.example.stlink.configs;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

/**
 * 主要用于建库和建表
 */
public class MySQLiteOpenHelper extends SQLiteOpenHelper {

    private final String SQL_CREATE_ENTRIES;
    private final String SQL_DELETE_ENTRIES;

    public MySQLiteOpenHelper(@Nullable Context context,
                              @Nullable String dbName,
                              @Nullable SQLiteDatabase.CursorFactory factory,
                              int version,
                              @Nullable String sqlCreateEntries,
                              @Nullable String sqlDeleteEntries) {
        super(context, dbName, factory, version);
        SQL_CREATE_ENTRIES = sqlCreateEntries;
        SQL_DELETE_ENTRIES = sqlDeleteEntries;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }
}
